
package com.dy.template;

import java.util.List;

import com.dy.model.Column;
import com.dy.model.Creator;
import com.dy.model.TableInfo;

/**
 * @Description:表单页面
 * @Date：2018年6月21日 @author： DongY
 * @version ：1.0 1.[2018年6月21日]CreatBy：dy
 */

public class HtmlAdd implements BaseSting {
	public int numInRow = 2;

	@Override
	public String getStr(final TableInfo tableInfo, final Creator c) {
		String string = "<script type='text/html' id='edit-tpl'>\r\n\t<div style='margin:10px'>"
				+ "\r\n\t\t<form class='layui-form' action='' lay-filter='form-edit'>";
		final List<Column> columns = tableInfo.getColumns();
		int i = 0;
		int j = 0;
		for (final Column column : columns) {
			j++;
			if (isSkip(column)) {
				continue;
			}
			if (i % numInRow == 0) {
				string += "\r\n\t\t\t<div class='layui-form-item'>";
			}
			string += "\r\n\t\t\t\t<div class='layui-inline'>";
			string += "\r\n\t\t\t\t\t<label class='layui-form-label'>" + column.getRemark() + "</label>";
			string += "\r\n\t\t\t\t\t<div class='layui-input-inline'>";
			string += "\r\n\t\t\t\t\t\t<input type='text' placeholder=''data-link='{:" + column.getJavaName()
					+ "}' id='$" + column.getJavaName() + "' name='" + column.getJavaName() + "' class='layui-input'>";
			string += "\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>";
			if (i % numInRow == numInRow - 1 || j == columns.size()) {
				string += "\r\n\t\t\t</div>";
			}
			i++;
		}
		string += "\r\n\t\t</form>\r\n\t</div>\r\n</script>";
		return string;
	}

	public static boolean isSkip(final Column column) {
		final boolean flg = false;
		if ("id".equals(column.getJavaName()) || column.isPRI()) {
			return true;
		}
		return flg;
	}

}
